package top.lixunda.books3.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.lixunda.books3.dao.BookMapper;
import top.lixunda.books3.entity.Book;
import top.lixunda.books3.entity.BookWithBLOBs;
import top.lixunda.books3.model.BookTag;
import top.lixunda.books3.model.SimpleBook;
import top.lixunda.books3.service.BookService;
import top.lixunda.books3.util.Log;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    private final BookMapper bookMapper;

    @Autowired
    public BookServiceImpl(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Override
    public BookWithBLOBs selectBookWithBLOBsById(long bookId) {
        return bookMapper.selectByPrimaryKey(bookId);
    }

    @Override
    public List<SimpleBook> selectSimpleBookListByBookTag(List<BookTag> bookTags, long page) {
        return bookMapper.selectSimpleBookByBookTags(bookTags, page * RecommendServiceImpl.PAGE_COUNT,
                RecommendServiceImpl.PAGE_COUNT);
    }

    @Override
    public void clickBookOnce(Book book) {
        bookMapper.updateBookClickTimes(book.getId());
        Log.d("________________>  书籍 "+book.getTitle()+" 点击次数加一");
    }

}
